package graphquerying.reachability;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import model.Graph;
import model.QueryManager;

/**
 * The test class of reachability querying
 * @author BaiJian
 */
public class ReachabilityTest {
	public static void main(String[] args) throws IOException {
		String nodeFileName = "dataset/data graph/node.txt";
		String edgeFileName = "dataset/data graph/redges.txt";
		Graph graph = Graph.loadFromTextFile(nodeFileName, edgeFileName, null, null);
		QueryManager qm = new QueryManager();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("please input source node's id and target node's id, separated with a space. Empty input will cause system exit:");
		String ids = in.readLine();
		while (!ids.isEmpty()) {
			String idArr[] = ids.split(" ");
			if (idArr.length != 2) {
				System.out.println("Invalid input");
			} else {
				boolean result = qm.reachabilityQuery(graph, "node_id_" + idArr[0] , "node_id_" + idArr[1]);
				if (result) {
					System.out.println("Reachable!");
				} else {
					System.out.println("Not reachable!");
				}
				
			}
			System.out.println("please input source node's id and target node's id, separated with a space. Empty input will cause system exit:");
			ids = in.readLine();
		}
		
	}
}
